package com.weixinli.web.actions;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.weixinli.beans.Article;
import com.weixinli.beans.FmArticle;
import com.weixinli.beans.Mood;
import com.weixinli.beans.PageInfo;
import com.weixinli.beans.UserInfo;
import com.weixinli.biz.IArticleBiz;
import com.weixinli.biz.IFmArticleBiz;
import com.weixinli.biz.IMoodBiz;
import com.weixinli.utils.SessionAttributeName;
import com.weixinli.web.actions.model.JsonObject;

@Controller("indexDataAction")
public class IndexDataAction extends ActionSupport implements SessionAware{
	private static final long serialVersionUID = 1L;
	
	private Map<String,Object> session;
	private FmArticle fmArticle;
	
	private JsonObject jsonObject;
	private IFmArticleBiz ifmArticleBiz;
	private IArticleBiz iArticleBiz;
	@Resource(name="iMoodBiz")
	private IMoodBiz moodBiz;
	
	public String indexData(){
		jsonObject=new JsonObject();
		getFMArticle();
		getArticle();
		getMood();
		jsonObject.setResult(1);
		return "success";
	}
	
	private void getMood() {
		List<Mood> list = moodBiz.getTotalMood();
		System.out.println(list);
		UserInfo uf = (UserInfo) session.get(SessionAttributeName.CURRENTUSER);
		if(uf!=null){
			session.put("moodNum", moodBiz.findFriendMood(uf.getW_uid()).size());
		}
		session.put(SessionAttributeName.MOODINFO, list);
	}
/*
	private void getTest(HttpServletRequest request,HttpServletResponse response) {
		List<Test> list=testBiz.getPageTest(null, null);
		session.setAttribute(SessionAttributeName.TESTINFO, list);
	}
*/
	/**
	 * 对于文章首页
	 */
	private void getArticle() {
		List<Article> list=iArticleBiz.getIndexArticle();
		session.put(SessionAttributeName.ARTICLEINFO, list);
		session.put(SessionAttributeName.CURRENTARTICLE, list);
	}
	/**
	 * 初始化音频
	 */
	private void getFMArticle() {
		List<FmArticle> list=ifmArticleBiz.findArticleIndex();
		session.put(SessionAttributeName.FMARTICLEINFO, list);
	}
	
	public void setSession(Map<String, Object> session) {
		this.session=session;
	}
	public void setFmArticle(FmArticle fmArticle) {
		this.fmArticle = fmArticle;
	}
	@Resource(name="ifmArticleBiz")
	public void setIfmArticleBiz(IFmArticleBiz ifmArticleBiz) {
		this.ifmArticleBiz = ifmArticleBiz;
	}
	public JsonObject getJsonObject() {
		return jsonObject;
	}
	public void setJsonObject(JsonObject jsonObject) {
		this.jsonObject = jsonObject;
	}
	@Resource(name="iArticleBiz")
	public void setiArticleBiz(IArticleBiz iArticleBiz) {
		this.iArticleBiz = iArticleBiz;
	}
}
